package com.weixx.swagger.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2//开启swagger2
public class SwaggerConfig {
    //配置了swagger的docket的bean实例
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //enabled() 配置释放启动swagger
                .select()
                //RequestHandleerSelector,配置要扫描的接口的方式
                //basePackage:指定要扫描的包
                //any()全部
                //none()不扫描
                //withClassAnnotation扫描类上的注解
                //withMethodAnnotation扫描方法上的注解
                //通过反射读取注解
                .apis(RequestHandlerSelectors.basePackage("com.weixx.swagger"))
                //path()过滤路径
                .build();
    }
    //配置swagger信息=apiInfo
    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("weixx", "https://user.qzone.qq.com/1121378061", "1121378061@qq.com");

        return new ApiInfo(
                "Api测试",
                "什么都没留下",
                "1.0",
                "https://user.qzone.qq.com/1121378061",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );
    }
}
